import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
// import 'package:flutter_bugly/flutter_bugly.dart';

class MyHomePage extends StatefulWidget {
  final String title;

  @override
  const MyHomePage({super.key, required this.title});

  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Uint8List? bytesData;

  // 本地加载资源
  int repeatCount = -1;
  bool isLoop = false;
  double slideValue = 0.0;
  bool autoPlay = false;

  late MethodChannel _channel;

  @override
  void initState() {
    _channel = const MethodChannel('multiple-flutters');
    _channel.setMethodCallHandler((call) async {
      if (call.method == "stop") {
        print('call.method == "stop');
        setState(() {});
      } else if (call.method == "start") {
        print('call.method == "start');
        setState(() {});
      } else {
        throw Exception('not implemented ${call.method}');
      }
    });
    super.initState();
  }

  void _simulateCrash() {
    // 模拟Dart层崩溃
    // throw Exception("自定义崩溃测试");
    // FlutterBugly.uploadException(
    //   type: '45454',
    //   message: '4564545',
    //   detail: '44224',
    //   data: {"source": "flutter_framework"},
    // );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: SingleChildScrollView(
            child: Center(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              ElevatedButton(
                onPressed: _simulateCrash,
                child: Text("触发测试崩溃"),
              ),
              TextButton(
                child: Text('video测试'),
                onPressed: () => {
                  _channel.invokeMethod<void>("nextPage", {'url': 'pages/DoubleFlutterPage'}),
                },
              ),
              TextButton(
                child: Text('webview测试'),
                onPressed: () => {
                  _channel.invokeMethod<void>("nextPage", {'url': 'pages/Webview'}),
                },
              ),
              TextButton(
                child: Text('sqflite测试'),
                onPressed: () => {
                  _channel.invokeMethod<void>("nextPage", {'url': 'pages/Sqflite'}),
                },
              ),
            ],
          ),
        )));
  }
}
